

function addSensorbitCod(Blockly) {






    //旋转编码器初始化
  Blockly.Python.microbit_encoderInit = function(block) {
    var dropdown_aPort = this.getFieldValue('aPort');
    var dropdown_bPort = this.getFieldValue('bPort');
    
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *\n';
    Blockly.Python.definitions_['import_encoder'] = 'from sensor import encoder\n';
    Blockly.Python.definitions_['import_encoderAPort'] = 'aPort = '+ dropdown_aPort ;
    Blockly.Python.definitions_['import_encoderBPort'] = 'bPort = '+ dropdown_bPort ;
    Blockly.Python.definitions_['import_encoderDPort'] = 'dPort = '+ dropdown_dPort ;
    return '';
  }

   //旋转编码器
   Blockly.Python.microbit_encoderButtonPressed = function(block) {
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *\n';
    Blockly.Python.definitions_['import_encoder'] = 'from input import encoder\n';
    var dropdown_dPort = this.getFieldValue('dPort');
    Blockly.Python.definitions_['import_encoderDPort' + dropdown_dPort] = 'dPort'+dropdown_dPort+' = '+ dropdown_dPort ;
    var code = 'encoder.is_pressed(dPort'+dropdown_dPort+')';
    return [code];
  }

  //旋转编码器
  Blockly.Python.microbit_encoderPulse = function(block) {
    var dropdown_aPort = this.getFieldValue('aPort');
    var dropdown_bPort = this.getFieldValue('bPort');
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *\n';
    Blockly.Python.definitions_['import_encoder'] = 'from input import encoder\n';
    Blockly.Python.definitions_['import_encoderAPort' + dropdown_aPort] = 'aPort'+dropdown_aPort+' = '+ dropdown_aPort ;
    Blockly.Python.definitions_['import_encoderBPort' + dropdown_bPort] = 'bPort'+dropdown_bPort+' = '+ dropdown_bPort ;
    var code = 'encoder.pulse(aPort'+dropdown_aPort+', bPort'+ dropdown_bPort +')';
    return [code];
  }

    return Blockly;
}

module.exports = addSensorbitCod;

